package com.wicket.okrframework.web.contorller;

import com.wicket.okrframework.biz.service.dto.spec.ArchiveSingleDataReqDto;
import com.wicket.okrframework.biz.service.dto.spec.ArchiveSingleDataRespDto;
import com.wicket.okrframework.biz.service.dto.spec.DeleteSingleDataComReqDto;
import com.wicket.okrframework.biz.service.dto.spec.DeleteSingleDataComRespDto;
import com.wicket.okrframework.common.annotations.BanAuto;
import com.wicket.okrframework.common.ro.OkrResult;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.dal.mapper.mbg.spec.NbMapper;
import com.wicket.okrframework.dal.po.mbg.NbParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author ：CHS
 * @since 2022/4/6 15:05
 *
 *
 * @version 1.0
 */
@RestController
@RequestMapping("/base/nb/")
@BanAuto
public class NbController {

    @Autowired
    NbMapper mapper;

    @PostMapping("archiveSingleData")
    @BanAuto
    public OkrResult<ArchiveSingleDataRespDto> archiveSingleData(@RequestBody @Validated ArchiveSingleDataReqDto req) {
        NbParam param = new NbParam();
        param.setTable(req.getObjectCode());
        param.setIdField(CommonFunctionHelper.humpToUnderline(req.getPropertyCode()));
        param.setIdValue(req.getUniqueId());
        param.setIsArchive("TRUE");
        param.setTime(CommonFunctionHelper.getCurrentTime());

        mapper.archiveSingleData(param);
        return OkrResult.success(null);
    }

    @PostMapping("deleteSingleDataCom")
    @BanAuto
    public OkrResult<DeleteSingleDataComRespDto> deleteSingleDataCom(@RequestBody @Validated DeleteSingleDataComReqDto req) {
        NbParam param = new NbParam();
        param.setTable(req.getObjectCode());
        param.setIdField(CommonFunctionHelper.humpToUnderline(req.getPropertyCode()));
        param.setIdValue(req.getUniqueId());

        mapper.deleteSingleDataCom(param);
        return OkrResult.success(null);
    }

}
